﻿using Admin.NET.Application.Const;
using Admin.NET.Application.Entity;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Authorization;
using System.Collections.Generic;

namespace Admin.NET.Application;
/// <summary>
/// 质感服务
/// </summary>
[AllowAnonymous]
[ApiDescriptionSettings(ApplicationConst.GroupNameApi, Order = 100)]
public class car_zhiganServiceApi : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<car_zhigan> _rep;
    public car_zhiganServiceApi(SqlSugarRepository<car_zhigan> rep)
    {
        _rep = rep;
    }

    /// <summary>
    /// 分页查询质感
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Page")]
    public async Task<SqlSugarPagedList<car_tag>> Page(car_zhiganInput input)
    {
        var query = _rep.Context.Queryable<car_tag>()
                    .Where(m => m.IsDelete == false && m.type == (int?)car_tagType.zhigan)
                  
;
        query = query.OrderBuilder(input);
        return await query.ToPagedListAsync(input.Page, input.PageSize);
    }

    /// <summary>
    /// 增加质感
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Add")]
    public async Task Add(Addcar_zhiganInput input)
    {
        var entity = input.Adapt<car_zhigan>();
        await _rep.InsertAsync(entity);
    }

    /// <summary>
    /// 删除质感
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Delete")]
    public async Task Delete(Deletecar_zhiganInput input)
    {
        var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
        await _rep.FakeDeleteAsync(entity);   //假删除
    }

    /// <summary>
    /// 更新质感
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Update")]
    public async Task Update(Updatecar_zhiganInput input)
    {
        var entity = input.Adapt<car_zhigan>();
        await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
    }

    /// <summary>
    /// 获取质感
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "Detail")]
    public async Task<car_zhigan> Get([FromQuery] QueryByIdcar_zhiganInput input)
    {
        return await _rep.GetFirstAsync(u => u.Id == input.Id);
    }

    /// <summary>
    /// 获取质感列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "List")]
    public async Task<List<car_zhiganOutput>> List([FromQuery] car_zhiganInput input)
    {
        return await _rep.AsQueryable().Select<car_zhiganOutput>().ToListAsync();
    }





}

